/*
 * 文件名：OpenSessionInViewFilter.java
 * 版权：Copyright by www.wootide.com
 * 描述：
 * 修改人：qianfm
 * 修改时间：Oct 8, 2012
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */
package com.wootide.cms.common.manager;

import org.hibernate.FlushMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.orm.hibernate3.SessionFactoryUtils;

/**
 * 〈一句话功能简述〉
 * 〈功能详细描述〉
 * @author qianfm
 * @version Oct 8, 2012
 * @see OpenSessionInViewFilter
 * @since
 */

public class OpenSessionInViewFilter extends
        org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
{
    
    /**
     * we do a different flushmode than in the codebase
     * here
     */
    protected Session getSession(SessionFactory sessionFactory)
            throws DataAccessResourceFailureException
    {
        Session session = SessionFactoryUtils.getSession(sessionFactory, true);
        session.setFlushMode(FlushMode.COMMIT);
        return session;
    }
    
    /**
     * we do an explicit flush here just in case
     * we do not have an automated flush
     */
    protected void closeSession(Session session, SessionFactory factory)
    {
        session.flush();
        super.closeSession(session, factory);
    }
}
